package com.sservice.commonBusiness.service.impl;

import com.sservice.commonBusiness.e.Category;
import com.sservice.commonBusiness.mapper.CategoryMapper;
import com.sservice.commonBusiness.service.CategoryService;
import com.sservice.commonBusiness.vo.CategoryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;


/**
 * Created by byte_su@163.com on 2018/01/12.
 */
@Service
public class CategoryServiceImpl implements CategoryService {

    @Autowired
    private CategoryMapper categoryMapper;

    @Override
    public int countByPage(CategoryVo category) {
        return categoryMapper.countByPage(category);
    }

    @Override
    public List<CategoryVo> queryByPage(CategoryVo category) {
        return categoryMapper.queryByPage(category);
    }

    @Override
    public Integer countPlainByPage(CategoryVo data) {
        return categoryMapper.countPlainByPage(data);
    }

    @Override
    public List<CategoryVo> queryPlainByPage(CategoryVo data) {
        return categoryMapper.queryPlainByPage(data);
    }

    @Override
    public List<Category> findByExample(Category category) {
        Example example = new Example(Category.class);

        if ("fi".equals(category.getType1())) { // 前端菜单 front-menu and info
            example.createCriteria()
                    .orEqualTo("type1", "front-menu")
                    .orEqualTo("type1", "info");
        } else {
            example.createCriteria().andEqualTo("type1", category.getType1() != null ? category.getType1() : "menu");

        }


        if (category.getStatus() == null) {
            example.createCriteria()
                    .orEqualTo("status", 1)
                    .orEqualTo("status", 2);
        } else {
            example.createCriteria().andEqualTo("status", category.getStatus());
        }

        return null;
    }


    @Override
    public List<CategoryVo> page(CategoryVo category) {
        return categoryMapper.queryByPage(category);
    }

    @Override
    public int deleteByPrimaryKey(Integer id) {
        return categoryMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insertSelective(Category record) {
        return categoryMapper.insertSelective(record);
    }

    @Override
    public Category selectByPrimaryKey(Integer id) {
        return categoryMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(Category record) {
        return categoryMapper.updateByPrimaryKeySelective(record);
    }


    @Override
    public Category selectBy(Category record) {
        return categoryMapper.selectBy(record);
    }
}
